<style>
	body{
		background: #f5f5f5;
	}
</style>
<div class="sectionY">
	<a href="javascript:history.back()">
		<img src="__PUBLIC__/home/images/a4.png" class="a1" alt="">
	</a>
	<p class="p1">团队奖兑换</p>
</div>
<div class="kong1"></div>
<div class="neng_section1">
	<p class="p1">提醒:</p>
	<p class="p2">1.1个团队奖兑换{:config('setting.atc_rate')}个资产 </p>
	<p class="p2">2.最少兑换{:config('setting.atc_start')}个团队奖，最大兑换{:config('setting.atc_end')}个团队奖</p>
</div>
<div class="neng_section2">
	<div class="neng_section2_1">
		<form action="">
			<div class="f1 clearfix">
				<p class="p1">剩余团队奖数量</p>
				<p class="p2">{$userinfo.wagesall}</p>
			</div>
			<div class="f1 clearfix">
				<p class="p1">兑换资产</p>
				<input type="number" name="salary" class="input1 input_plc" placeholder="请输入兑换团队奖数量">
			</div>
			<div class="f1 clearfix">
				<p class="p1">交易密码</p>
				<input type="number" class="input1 input_plc" name="pwd" placeholder="请输入交易密码">
			</div>
			<div class="sub">
				<button type="button" id="submit">确认兑换</button>
				<a href="javascript:history.back();" class="a1">取消</a>
				<p class="p1">提示：请先通过实名认证再进行转赠</p>
			</div>
		</form>
	</div>
</div>
<script>
	$(function(){
		$('#submit').click(function(){
			var num = $('input[name=salary]').val();
			var pwd = $('input[name=pwd]').val();
			if(num==''){
				layer.alert('请检查您要兑换的资产数量，资产兑换不能为空！',{icon: 2,shade:0.8,title:"错误提示:"});return false;
			}
			if(pwd==''){
				layer.alert('请输入交易密码！',{icon: 2,shade:0.8,title:"错误提示:"});return false;
			}
			$.ajax({
				type: 'POST',
				url: "{:url('User/atcChange')}",
				dataType: "html",
				data: "num="+num+"&pwd="+pwd,
				success:function(responsestr){
					var str = isJSON(responsestr);
					if(str==1){
						var obj=JSON.parse(responsestr);
						if(obj.s==10){
							layer.msg('成功！',{shade:0.6,time:1000,end:function(){
									window.location.href=window.location.href;
									return false;
								}});
						}else{
							layer.alert(obj.msg,{shade:0.2});return false;
						}
					}else{
						layer.alert('系统正忙，请稍后再试！',{shade:0.2});
					}
				},
				error:function(){
					layer.alert('系统繁忙，请稍后再试！',{shade:0.2});
				}
			});
		});
	})

	function isJSON(str) {
		if (typeof str == 'string') {
			try{
				var obj=JSON.parse(str);
				if(str.indexOf('{')>-1){
					return 1;
				}else{
					return 0;
				}
			}catch(e){
				return 0;
			}
		}
		return 0;
	}
</script>
